﻿using System;
using System.Data;
using System.Collections.Generic;
using DataLib.Common;
using DataLib.Model;
namespace DataLib.BLL
{
	/// <summary>
	/// ProjectsRelation
	/// </summary>
	public partial class ProjectsRelation
	{
		private readonly DataLib.DAL.ProjectRelation dal=new DataLib.DAL.ProjectRelation();
		public ProjectsRelation()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int? id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(DataLib.Model.ProjectsRelation model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(DataLib.Model.ProjectsRelation model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int? id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			return dal.DeleteList(IDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DataLib.Model.ProjectsRelation GetModel(int? id)
		{
			
			return dal.GetModel(id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public DataLib.Model.ProjectsRelation GetModelByCache(int? id)
		{
			
			string CacheKey = "ProjectsRelationModel-" + id;
            object objModel = DataLib.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
                        int ModelCache = DataLib.Common.ConfigHelper.GetConfigInt("ModelCache");
                        DataLib.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (DataLib.Model.ProjectsRelation)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DataLib.Model.ProjectsRelation> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DataLib.Model.ProjectsRelation> DataTableToList(DataTable dt)
		{
			List<DataLib.Model.ProjectsRelation> modelList = new List<DataLib.Model.ProjectsRelation>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				DataLib.Model.ProjectsRelation model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
				}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod
       /// <summary>
        /// 根据用户名取得名下所有可开CJO
        /// </summary>
        /// <param name="uerName"></param>
        /// <param name="typeflag">
        /// 参数 @getTye 0 取得@username权限 如果admin 1(开cjo)_1(授权)_1(查看) 
        ///				 1 取得@username的开CJO列表
        ///				 2 取得@username的CJO授权列表
        ///				 3 取得@username的查看列表</param>
        /// <returns></returns>
        public DataTable getAddressByUserName(string uerName, int typeflag)
        {
            return dal.getAddressByUserName(uerName, typeflag);
        }
        /// <summary>
        /// 级联删除
        /// </summary>
        /// <param name="AddressID">地址编号</param>
        /// <param name="ServerPointID">服务点编号</param>
        /// <param name="ServerAreaID">服务区域编号</param>
        /// <param name="ProjectID">项目编号</param>
        /// <param name="DelType">删除类型(1只删除地址,2删除地址和服务点,3删除地址、服务点和区域,4删除地址、服务点、区域和项目)</param>
        public void RelationDelete(int AddressID, int ServerPointID, int ServerAreaID, int ProjectID, int DelType)
        {
            dal.RelationDelete(AddressID, ServerPointID, ServerAreaID, ProjectID, DelType);
        }

                /// <summary>
        /// 根据客户ID取得客户名下项目列表
        /// </summary>
        /// <param name="uerName"></param>
        /// <param name="typeflag">
        /// 参数 @getTye 0 取得@username权限 如果admin 1(开cjo)_1(授权)_1(查看) 
        ///				 1 取得@username的开CJO列表
        ///				 2 取得@username的CJO授权列表
        ///				 3 取得@username的查看列表</param>
        ///	<param name="cumid">客户ID</param>
        /// <returns></returns>
        public DataTable getAddressByUserName(string uerName, int typeflag, int cumid)
        {
            return dal.getAddressByUserName(uerName, typeflag, cumid);
        }

        
        /// <summary>
        /// 根据客户ID取得客户名下项目列表
        /// </summary>
        /// <param name="uerName"></param>
        /// <param name="typeflag">
        /// 参数 @getTye 0 取得@username权限 如果admin 1(开cjo)_1(授权)_1(查看) 
        ///				 1 取得@username的开CJO列表
        ///				 2 取得@username的CJO授权列表
        ///				 3 取得@username的查看列表
        ///				 4 
        ///				 5
        ///				 6 取得@username的Load列表</param>
        ///	<param name="cumid">客户ID</param>
        /// <returns></returns>
        public DataTable getAddressByUserName(string uerName, int typeflag, int proid, int cumid)
        {
            return dal.getAddressByUserName(uerName, typeflag, proid, 0);
        }

               /// <summary>
        /// 根据用户名取得名下所有项目或者区域
        /// </summary>
        /// <param name="uerName"></param>
        /// <param name="typeflag">
        /// 参数 @getTye 
        ///				 1 取得@username的项目列表
        ///				 2 取得项目下面的的服务点
        ///				 3 取得@username的查看列表
        ///	</param>
        /// <returns></returns>
        public DataTable getProjectByUserName(string uerName, int typeflag)
        {
            return dal.getProjectByUserName(uerName, typeflag);
        }
         public DataTable GetProjectDetailsByStore(string uerName, int currpage, int length, out int totalRecord,
                                                   string search,string city, string order_column, string order_dir,string uname)
         {
             return dal.GetProjectDetailsByStore(uerName, currpage, length, out totalRecord, search, city,  order_column,  order_dir,uname);
         }
		#endregion  ExtensionMethod
	}
}

